<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="linuxbox.bookmark.logic.*" %>


<%

  int ENTRIES_IN_HOMEPAGE = sec.getConfigInt("bookmark", "HomePage", "Entries in HomePage");
  int ENTRIES_PER_PAGE = sec.getConfigInt("bookmark", "General", "Entries Per Page");

  String entries[] = sec.getConfigStrings("bookmark", "HomePage", "Entries");

  BookmarkHome home = BookmarkHome.getInstance();
  Collection userBookmarks = home.getBookmarks(curID, home.VT_MINE, "name", true, 0, Integer.MAX_VALUE);
  Collection systemBookmarks = home.getBookmarks(curID, home.VT_SYSTEM, "name", true, 0, Integer.MAX_VALUE);
  Collection homePageBookmarks = home.getBookmarks(entries);

%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<script LANGUAGE="JavaScript">
function onAdd(options)
{
  if ( options.length > 0)
  {
    for (i=0; i<options.length;i++)
    {
      var curLenght = document.theForm.HOMEPAGE_ENTRIES.length;
      if (options[i].selected == true)
      {
        var found = false;
        for(j=0; j < curLenght; j++)
        {
          if (document.theForm.HOMEPAGE_ENTRIES.options[j].value == options[i].value)
          {
            found = true;
            break;
          }
        }
        if (!found)
        {
          var option = new Option(options[i].text, options[i].value);
          document.theForm.HOMEPAGE_ENTRIES.options[curLenght] = option;
        }
      }
    }
  }
}

function onRemove()
{
  var options = document.theForm.HOMEPAGE_ENTRIES;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      if (options[i].selected == true)
        options[i] = null;
    }
  }
}

//select all the items so they will be sent out
function onSubmit()
{
//	alert("Set selected");
  var options = document.theForm.HOMEPAGE_ENTRIES.options;
  if ( options.length > 0)
  {
    for (i=options.length-1; i >=0; i--)
    {
      options[i].selected = true;
    }
//		alert("Set selected");
  }
}
</script>

<form action="<%=BoxStatic.servletDir%>BookmarkSettingsAction" method=POST name=theForm >
  <table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
    <tr>
      <td>
        &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
        <b><%=boxName%> - Bookmark Settings</b>
      </td>
    </tr>
  </table>

<hr width=\"100%\" color=#E06000 align=left>

  <TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
    <tr><th align=left bgcolor="#7EC1F3" >
      <font size="+1">General:</font>
    </th></tr>
    <tr><td>
      Display
          <select name="ENTRIES_PER_PAGE" size="1" >
            <OPTION value=10 <% if (ENTRIES_PER_PAGE==10) out.print("selected");%>>10</OPTION>
            <OPTION value=20 <% if (ENTRIES_PER_PAGE==20) out.print("selected");%>>20</OPTION>
            <OPTION value=30 <% if (ENTRIES_PER_PAGE==30) out.print("selected");%>>30</OPTION>
            <OPTION value=50 <% if (ENTRIES_PER_PAGE==50) out.print("selected");%>>50</OPTION>
            <OPTION value=100 <% if (ENTRIES_PER_PAGE==100) out.print("selected");%>>100</OPTION>
            <OPTION value=200 <% if (ENTRIES_PER_PAGE==200) out.print("selected");%>>200</OPTION>
          </select>
         entries per page.
    </td></tr>

    <tr><th align=left bgcolor="#7EC1F3">
      <font size="+1">Homepage:</font>
    </th></tr>
    <tr><td>
      Display
          <select name="ENTRIES_IN_HOMEPAGE" size="1" >
            <OPTION value=2 <% if (ENTRIES_IN_HOMEPAGE==2) out.print("selected");%>>2</OPTION>
            <OPTION value=4 <% if (ENTRIES_IN_HOMEPAGE==4) out.print("selected");%>>4</OPTION>
            <OPTION value=5 <% if (ENTRIES_IN_HOMEPAGE==5) out.print("selected");%>>5</OPTION>
            <OPTION value=6 <% if (ENTRIES_IN_HOMEPAGE==6) out.print("selected");%>>6</OPTION>
            <OPTION value=10 <% if (ENTRIES_IN_HOMEPAGE==10) out.print("selected");%>>10</OPTION>
            <OPTION value=20 <% if (ENTRIES_IN_HOMEPAGE==20) out.print("selected");%>>20</OPTION>
          </select>
         entries in Home page.
    </td></tr>
  </table>


  <table width="100%" border="1">
    <tr>
      <td>
        <table width="100%" border="0">
          <tr valign="middle"> 
            <td valign="top"> User defined bookmarks:<br>
              <select name="USERBOOKMARKS" size="6" multiple>
<%
  if (userBookmarks != null && !userBookmarks.isEmpty())
  {
    Iterator it= userBookmarks.iterator();
    while (it.hasNext())
    {
      BookmarkEntry entry= (BookmarkEntry) it.next();
      out.print("<option value="+entry.getID()+">"+entry.getName()+"</option>");
    }
  }
%>
              </select>
	  	      </td>
			      <td size="1%">
              <input type="button" name="Button" value="=>" onClick="onAdd(document.theForm.USERBOOKMARKS)">
            </td>
          </tr>
          <tr>
            <td valign="top">System defined bookmarks:<br>
              <select name="SYSTEMBOOKMARKS" size="6" multiple>
<%
  if (systemBookmarks != null && !systemBookmarks.isEmpty())
  {
    Iterator it= systemBookmarks.iterator();
    while (it.hasNext())
    {
      BookmarkEntry entry= (BookmarkEntry) it.next();
      out.print("<option value="+entry.getID()+">"+entry.getName()+"</option>");
    }
  }
%>
              </select>
            </td>
			      <td size="1%">
              <input type="button" name="Button" value="=>" onClick="onAdd(document.theForm.SYSTEMBOOKMARKS)">
            </td>
          </tr>
        </table>
      </td>
      <td valign="top"> Show following bookmarks in homepage:<br>
        <select name="HOMEPAGE_ENTRIES" size="10" multiple>
<%
  if (homePageBookmarks != null && !homePageBookmarks.isEmpty())
  {
    Iterator it= homePageBookmarks.iterator();
    while (it.hasNext())
    {
      BookmarkEntry entry= (BookmarkEntry) it.next();
      out.print("<option value="+entry.getID()+">"+entry.getName()+"</option>");
    }
  }
%>
        </select><br>
        <input type="button" name="Button" value="Remove" onClick="onRemove()">
      </td> 
    </tr>

    <tr>
      <td colspan=2>
        <input type=submit value="Save" onclick="onSubmit()" name=SubmitSave>
        <input type=submit value="Cancel" name=SubmitCancel>
      </td>
    </tr>
  </table>
</form>

<hr width=\"100%\" color=#E06000 align=left>
<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
